import { ReqPages, ReqsUserList, ReqsUserParams, ResPage, ResPages, User, ChangePwdParams } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";
import httpss from "@/api/http";

/**
 * @name 用户管理模块
 */
// 获取用户列表
export const getUserList = (params: User.ReqUserParams) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
};
export const getList = (params: ReqsUserParams) => {
  return httpss.post<ReqPages>(`/user/list`, params);
};
export const getLists = () => {
  return httpss.get(`/user/all`);
};

// 获取树形用户列表
export const getUserTreeList = (params: User.ReqUserParams) => {
  return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/tree/list`, params);
};

// 新增用户
export const addUser = (params: { id: string }) => {
  console.log("新增用户", params);
  return http.post(PORT1 + `/user/add`, params);
};
export const addUsers = (params: User.ResUserList) => {
  console.log("新增用户 ", params);
  return httpss.post(`/user/add`, params);
};
// 批量添加用户
export const BatchAddUser = (params: FormData) => {
  console.log("数据", FormData);
  return http.post(PORT1 + `/user/import`, params);
};

// 编辑用户
export const editUser = (params: { id: string }) => {
  return http.post(PORT1 + `/user/edit`, params);
};

export const update = (params: User.ResUserList) => {
  console.log("数据编辑", params);
  return httpss.put(`/user/update`, params);
};
// 删除用户
export const deleteUser = (params: { id: string[] }) => {
  console.log("删除用户的id", params);
  return http.post(PORT1 + `/user/delete`, params);
};
// 新添的删除用户新接口
export const deleteUserId = (params: { id: string }) => {
  return httpss.delete(`/user/delete`, { params });
};
// 批量删除
export const deleteListId = (params: { id: string[] }) => {
  console.log("删除用户的id", params);
  return httpss.post(`/user/deleteList`, params);
};

// 切换用户状态
export const changeUserStatus = (params: { id: string; status: number }) => {
  return http.post(PORT1 + `/user/change`, params);
};

// 重置用户密码
export const resetUserPassWord = (params: { id: number }) => {
  return http.post(PORT1 + `/user/rest_password`, params);
};

export const resetUserPword = (params: { id: number }) => {
  console.log("重置密码的数据所带参数", params);
  return httpss.post(`/user/resetPassword`, params);
};

// 导出用户数据
export const exportUserInfo = (params: User.ReqUserParams) => {
  return http.download(PORT1 + `/user/export`, params);
};

// 获取用户状态字典
export const getUserStatus = () => {
  return http.get<User.ResStatus[]>(PORT1 + `/user/status`);
};

export const getUserGender = () => {
  return httpss.get(`/user/gender`);
};

// 获取用户部门列表
export const getUserDepartment = () => {
  return http.get<User.ResDepartment[]>(PORT1 + `/user/department`, {}, { cancel: false });
};
//更新密码
export const ChangePassword = (params: ChangePwdParams) => {
  console.log("修改密码", params);
  return httpss.post(`/user/changePassword`, params);
};

//角色接口
export const getUserRole = () => {
  return httpss.get(`/user/role`);
};
